package com.df.ez_game.server.gateway.tcp;

import com.df.ez_game.server.BrokerManager;
import com.df.ez_game.server.msg.client.ClientReqMsg;
import com.df.ez_game.server.gateway.UserManager;
import com.df.ez_game.server.gateway.UserSession;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class TcpGateWayForwarding extends SimpleChannelInboundHandler<ClientReqMsg> {
    BrokerManager brokerManager;
    public TcpGateWayForwarding(BrokerManager brokerManager) {
        this.brokerManager = brokerManager;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, ClientReqMsg gateWayReqMsg) throws Exception {
        //获取用户唯一id(没登录用channelid ，登录了用userid)
        String longText = channelHandlerContext.channel().id().asLongText();
        UserSession session = UserManager.getSessionByChannelId(longText);
        //TODO 用DPDK技术绕过内核协议栈（需配合Netty Native）
        //转换成内部消息，转发给broker
        brokerManager.forwarding(channelHandlerContext,gateWayReqMsg,session);
    }
}
